<!DOCTYPE html>
<html lang="en" class="h-100">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>ESP Launchpad</title>
        <!-- Favicon-->
        <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
        <!-- Core theme CSS (includes Bootstrap)-->
        <link href="css/styles.css" rel="stylesheet" />
        <link href="css/custom.css" rel="stylesheet" />
        <link href="css/xterm.css" rel="stylesheet" />
    </head>
    <body class="d-flex flex-column h-100">
         <!-- Modal for flashiing status-->
        <div class="container" id="mainContainer">

            <button type="button" class="btn btn-info btn-lg" data-bs-toggle="modal" data-bs-target="#myModal" id="statusModal" hidden>Open Modal</button>
            <div class="modal fade" id="myModal" role="dialog">
              <div class="modal-dialog modal-lg">

                <!-- Modal content-->
                <div class="modal-content">
                  <div class="modal-header">
                    <img src="./assets/esp-logo.png" width="42" height="42" style="vertical-align:middle"></img>&emsp;
                    <h4 class="modal-title"><span style="color: #17a2b8;"> ESP Firmware Flashing Status </span></h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="closeFlashComplete"></button>
                  </div>
                  <div class="modal-body" id="preview_body">
                    <div><p>Flashing of firmware is completed! Click the <b>'Reset Device'</b> button on the Console Tab to reset your device with the new flashed firnware.
                      <br><br>
                      <span id="appDownloadLink"></span>
                    </p>
                    </div>
                    <hr>
                    <div id='qrcodeContainer' style='display:flex'>
                        <div id="qrAndroidRow">
                            <div id="androidAppLogo" style="padding-bottom: 5px;"></div>
                            <div id='qrcodeAndroidApp' style="padding-right: 40px;"></div>
                        </div>
                        <div id="qrIOSRow">
                            <div id="iosAppLogo" style="padding-bottom: 5px;"></div>
                            <div id='qrcodeIOSApp'></div>
                        </div>
                    </div>
                  </div>
                  <div class="modal-footer">
                    <button class="app-button btn btn-outline-dark" type="button" id="done" data-bs-dismiss="modal">Done</button>
                  </div>
                </div>
              </div>
            </div>
        </div>
        <!-- Modal for flashing status section ends-->

        <!-- Modal for reset device starts-->
        <div class="container" id="mainContainer">

            <button type="button" class="btn btn-info btn-lg" data-bs-toggle="modal" data-bs-target="#resetModal" id="resetConfirmation" hidden>Open Modal</button>
            <div class="modal fade" id="resetModal" role="dialog">
              <div class="modal-dialog modal-lg">

                <!-- Modal content-->
                <div class="modal-content">
                  <div class="modal-header">
                    <img src="./assets/esp-logo.png" width="42" height="42" style="vertical-align:middle"></img>&emsp;
                    <h4 class="modal-title"><span style="color: #17a2b8;"> ESP Reset Device Confirmation </span></h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="closeResetModal"></button>
                  </div>
                  <div class="modal-body" id="preview_body">
                    <div id="resetMessage">
                        <p>This will reset your device. Click on 'Confirm' to continue.</p>
                        <button class="app-button btn btn-outline-dark" type="button" id="resetButton" data-toggle="tooltip"
                        data-placement="right" title="Confirm to Reset your device">Confirm</button>
                        <div><br></div>
                    </div>
                  </div>
                  <div class="modal-footer">

                  </div>
                </div>
              </div>
            </div>
        </div>

    <div id="main">
        <!-- Responsive navbar-->
        <nav class="navbar navbar-expand-lg">
            <div class="container">
                <h4 class="topic"  data-target-tab-panel-id="about">
                    <img src="assets/logo-v1.png" class="logo" />
                </h4>
                <!-- <span>A serial flasher utility for Espressif chips</span> -->
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                        <li class="nav-item active" data-role="nav-menu-tab" data-target-tab-panel-id="quickstart">
                            <button class="nav-link icon-button">
                                <img src="assets/icons/quickstart.png" class="icon" />
                                <span>Quick Start</span>
                            </button>
                        </li>

                        <li class="nav-item" data-role="nav-menu-tab" data-target-tab-panel-id="diy">
                            <button class="nav-link icon-button">
                                <img src="assets/icons/diy.png" class="icon" />
                                <span>DIY</span>
                            </button>
                        </li>
                        
                        <li class="nav-item">
                            <button class="nav-link icon-button" id="connectButton">
                                <img src="assets/icons/connect.png" class="icon" />
                                <span>Connect</span>
                            </button>
                            <button class="nav-link icon-button" id="disconnectButton">
                                <img src="assets/icons/disconnect.png" class="icon" />
                                <span>Disconnect</span>
                            </button>
                        </li>
                        
                        <li class="nav-item" data-role="nav-menu-tab" data-target-tab-panel-id="console">
                            <button class="nav-link icon-button" id="v-pills-console-tab">
                                <img src="assets/icons/console.png" class="icon" />
                                <span>Console</span>
                            </button>
                        </li>

                        <li class="nav-item" data-role="nav-menu-tab" data-target-tab-panel-id="settings">
                            <button class="nav-link icon-button">
                                <img src="assets/icons/settings.png" class="icon" />
                                <span>Settings</span>
                            </button>
                        </li>

                        <li class="nav-item" data-role="nav-menu-tab" data-target-tab-panel-id="about">
                            <button class="nav-link icon-button" id="aboutButton">
                                <img src="assets/icons/about-us.png" class="icon" />
                                <span>About</span>
                            </button>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <!-- Page content-->
        <div class="container" id="alert-container">
            <div class="text-center mt-3 intro-text">
                <div class="alert alert-warning alert-dismissible fade show" role="alert">
                    <label style="display:none" id="lblConnTo"><b>Connected to device: </b></label>
                    <p><span>ESP Launchpad helps you to flash the selected firmware image onto your device.</span>
                    <br /><span id="ensureConnect"> Ensure you have connected your device to the serial USB port. Click on the 'Connect' button in the top menu option, to connect to your attached device.
                        Note : Once you flash your device, any earlier firmware would be overwritten.</span>
                    </p>

                </div>
            </div>
        </div>

        <!-- Quick start tab content - start -->
        <div class="container tabs-section main-page-tab-panel" data-tab-panel-id="quickstart">
            <h5 class="pt-4 pb-2 lh-lg"><span id="qtLabel">Choose from some of ESP's pre-built, out-of-the-box examples to flash and play</span></h5>
            <div class="form">
                <div class="field-container">
                    <label>
                        Select Application
                    </label>
                    <div class="field">
                        <select name="device" id="device">
                            <option value="Matter-AllClustersApp">Matter-AllClustersApp</option>
                            <option value="RainMaker-Fan">RainMaker-Fan</option>
                            <option value="RainMaker-GPIO">RainMaker-GPIO</option>
                            <option value="RainMaker-HomekitSwitch">RainMaker-HomekitSwitch</option>
                            <option value="RainMaker-LedLight">RainMaker-LedLight</option>
                            <option value="RainMaker-MultiDevice">RainMaker-MultiDevice</option>
                            <option value="RainMaker-Switch">RainMaker-Switch</option>
                            <option value="RainMaker-TemperatureSensor">RainMaker-TemperatureSensor</option>
                        </select>
                    </div>
                </div>
                
                <div class="field-container">
                    <label>
                        ESP Chipset Type
                    </label>
                    <div class="field">
                        <div id="chipsets">
                            <div class="form-check-inline">
                                <label class="form-check-label" for="radio1">ESP32&nbsp;
                                    <input type="radio" checked class="form-check-input" name="chipType" id="radio1" value="esp32_matter_all-clusters-app_te6_merged.bin">
                                </label>
                            </div>
                            <div class="form-check-inline">
                                <label class="form-check-label" for="radio2">ESP32-C3&nbsp;
                                    <input type="radio" class="form-check-input" name="chipType" id="radio2" value="esp32c3_matter_all-clusters-app_te6_merged.bin">
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="field-container">
                    
                    <div class="field-container" title="Click on 'Connect' button in top Menu" style="display:inline-block" data-toggle="tooltip" id="flashWrapper">
                        <button class="app-button submit-form-button btn btn-outline-dark" id="flashButton" disabled>Flash</button>
                    </div>
                </div>
                <div class="field-container">
                    <span id="progressMsgQS" style="display:none"><i>This may take a short while. Check console for the progress</i></span>
                </div>
                <br><br>
                <div>
                    <div id='qrcodeContainerQS' style='display:flex'>
                        <div id="qrAndroidRowQS">
                            <div id="androidAppLogoQS" style="padding-bottom: 5px;"></div>
                            <div id='qrcodeAndroidAppQS' style="padding-right: 40px;"></div>
                        </div>
                        <div id="qrIOSRowQS">
                            <div id="iosAppLogoQS" style="padding-bottom: 5px;"></div>
                            <div id='qrcodeIOSAppQS' style="padding-bottom: 40px;"></div>
                        </div>
                    </div>
                </div>
                <br> <br>
            </div>
        </div>
        <!-- Quick start tab content - end -->

        <!-- DIY tab content - start -->
        <div class="container tabs-section main-page-tab-panel" data-tab-panel-id="diy">
            <h5 class="pt-4 pb-2 lh-lg">Choose your own built firmware image from the local storage to flash and use.</h5>
                <br>
                <input class="btn btn-danger btn-sm" type="button" id="eraseButton" value="Erase Flash" data-toggle="tooltip" 
            data-placement="top" title="Erase firmware on your device"/>
                
                <div class="alert alert-danger alert-dismissible fade-in-down" id="alertDiv" style="display:none; margin-top:10px">
                    <a href="#" class="close" aria-label="close" onclick="$('.alert').hide()">&times;</a>
                    <span id="alertmsg"></span>
                </div>
                <div id="files">
                    <table id="fileTable">
                        <thead>
                            <tr>
                                <th>Flash Address</th>
                                <th>Selected File</th>
                                <th>&nbsp;</th>
                            </tr>
                        </thead>
                        <tbody id="tableBody">
                            <tr id="row0">
                                <td class="input-col"><input type="text" id="offset1" name="offset1" value="0x1000"></td>
                                <td class="input-col"><input type="file" id="selectFile1" name="selected_file1"></td>
                                <td><input type="image" src="assets/icons/remove.png"></td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="button-container text-end mb-sm-3">
                        <button type="button" class="app-button submit-form-button btn btn-outline-dark" id="addFile"
                        data-toggle="tooltip" data-placement="right" title="Add another file to flash set" style="margin-right:10px;">Add File</button>
                    <div class="field-container" data-toggle="tooltip" data-placement="right" title="Click on 'Connect' button in top menu" id="programwrapper" style="display:inline-block">
                        <button type="button" class="app-button submit-form-button btn btn-outline-dark" id="programButton" disabled>Program</button>
                    </div>
                    </div>
                </div>
                <output id="list"></output>
                <hr/>
                <span id="progressMsgDIY" style="display:none"><i>This may take a short while. Check console for the progress</i></span>
        </div>
        <!-- DIY tab content - end -->

        <!-- Console tab content - start -->    
        <div class="container main-page-tab-panel" data-tab-panel-id="console">
            <div class="row">
                <div class="col-xs-12 ">
                    <div class="button-container text-end mb-sm-3">
                        <div class="field-container" data-toggle="tooltip" data-placement="right" title="Reset your device" style="display:inline-block">
                            <button type="button" class="app-button btn btn-outline-dark" id="consoleStartButton"  disabled
                            >Reset Device</button>
                        </div>
                    </div>
                    <div class="fade-in-down" id="terminal"></div>
                </div>
            </div>
        </div>
        
        <!-- Console tab content - end -->
        
        <!-- Settings tab content - start -->
        <div class="container main-page-tab-panel" data-tab-panel-id="settings">
            <div class="row">
                <div class="col-xs-12 ">
                    <div class="form">
                        <div id="baudRateSetting" class="lh-lg">
                            <span><b>Change the Baudrate to set the serial communication speed:</b></span>
                        </div>
                        <hr/>
                        <div class="field-container">
                            <label>
                                Baudrate
                            </label>
                            <div class="field" id="baudSettings">
                                <select name="baudrates" id="baudrates">
                                    <option value="921600">921600</option>
                                    <option value="460800">460800</option>
                                    <option value="230400">230400</option>
                                    <option value="115200">115200</option>
                                </select>
                            </div>
                        </div>
                        <div id="settingsWarning" style="display:none">
                            <span><i> ** Settings cannot be changed for a connected device. Please disconnect the device and then change the settings.</i></span>
                        </div>
                    </div>     
                </div>
            </div>
        </div>
        <!-- Settings tab content - end -->

        <!-- About us tab content - start -->
        <div class="container main-page-tab-panel mt-5 about-container" data-tab-panel-id="about">
            <div class="row">
                <div class="col-xs-12">
                    <span>
                        ESP Launchpad is a web based tool, available for flashing firmware application to the ESP32 device connected via
                        USB serial port.
                    </span>
                    <p>
                        There are two modes available for using this tool:
                        <ul>
                          <li><a class="anchor" href="#qsDiv">Quick Start</a> : 4 Easy Steps - Plug, Connect, Choose Built-In Firmware Image, Flash!</li>
                          <li><a class="anchor" href="#diyDiv">DIY</a> : For Advanced Users, use your own pre-built Firmware Image from local storage and Flash!</li>
                        </ul>

                        You can even build and <a class="anchor" href="#publishDiv">Publish your own Apps </a> for ESP32 using ESP Launchpad.
                    </p>
                </div>
                <!-- Quick Try -->
                <div class="col-xs-12 mt-5 " id="qsDiv">
                    <h4 class="topic mb-4"><b>Quick Start</b></h4>
                    <p>
                        ESP currently provides a few built in, ready to use examples that can be flashed on the ESP32 devices. You can
                        choose one of the built in firmware application for either RainMaker or Matter, and as per the chipset type.
                        Just plug in your ESP32 device to the serial USB port. Use connect option in the menu to connect to your ESP32 device. Choose
                        the firmware from the built-in firmware example set. Click Flash!
                    </p>
                    <p>The firmware will be flashed on to your connected device. You can watch the progress of the firmware flashing in
                        the console window.</p>
                    <p>This easy, 4 step process will flash the firmware on to the connected device and bring it into play as you want it to be.</p>
                    <h6 class="trynow mb-4" data-target-tab-panel-id="quickstart"><b>Try Now !</b></h6>
                </div>
                <!-- DIY -->
                <div class="col-xs-12 mt-5 " id="diyDiv">
                    <h4 class="topic mb-4" ><b>DIY</b></h4>
                    <p>
                        You can build your own firmware binaries using the ESP IDF tools. These firmware images can then be flashed from
                        your local machine to the connected device. Just connect your ESP32 device to the serial USB port. Using the web
                        based tool, connect to your device. You can then select the firmware application from the local storage of the
                        machine. Choose the memory address where to flash the firmware. Firmware can be a single file or a set of
                        multiple files to be flashed at particular memory addresses.
                    </p>
                    <p><b>Click Flash!</b></p>
                    <p>The firmware will be flashed on to your connected device. You can watch the progress of the firmware flashing in
                        the console window.
                    </p>
                    <h6 class="trynow mb-4" data-target-tab-panel-id="diy"><b>Try Now !</b></h6>
                </div>
                <!-- Publish your own firmware apps -->
                <div class="col-xs-12 mt-5" id="publishDiv">
                    <h4 class=" mb-4" style="color: #e63f36;"><b>Publish your own firmware apps</b></h4>
                    <p>ESP Launchpad also lets you easily publish your firmware apps for others to try.</p>

                    <p>The ESP Launchpad Quick Start page would be rendered by referring to a TOML configuration file, where you can configure where to pick
                    all the component images of your firmware, and the supported hardware. You could also link to any support phone apps to work along with
                    this firmware. A sample TOML config file can be viewed <a href="https://espressif.github.io/esp-launchpad/config/config.toml"> here </a> </p>

                    <p>Rest of the flashing procedure is same easy 4 step process as the Quick Start one above.</p>
                        
                    <p>Once ready, you can use the following image and add following html code on your website for supporting ESPaunchpad with your configuration.
                        Edit the query parameter in the href, replacing URL_TO_YOUR_CONFIG_TOML value where your TOML config file is hosted.
                    </p>
                    <div style="padding-bottom: 40px;">
                        <div style="padding-bottom: 10px;">
                            <img alt="Try it with ESP Launchpad" src="./assets/try_with_launchpad.png"
                            width="250" height="70">
                        </div>
                        <div>
                            <textarea readonly cols="160" rows="3"><a href="https://espressif.github.io/esp-launchpad/?flashConfigURL=URL_TO_YOUR_CONFIG_TOML">
    <img alt="Try it with ESP Launchpad" src="https://espressif.github.io/esp-launchpad/assets/try_with_launchpad.png" width="250" height="70">
</a>
                            </textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- About us tab content - end -->
    </div>
    
    <!-- Safari & FireFox not supported error message-->
    <div id="unsupportedBrowserErr" style="display:none"><p align="center" style="color:red">
        This tool is not supported on Safari & Firefox browsers yet! Please try using another browser like Google Chrome.
            <br> <br>
            ESP Launchpad makes use of WebUSB to communicate with the device. Currently Safari & Firefox browsers don't support it yet.

            We will add support for this browser as soon as Safari & Firefox starts supporting WebUSB.

    </p>
    </div>

        <footer class="mt-auto py-3">
            <div class="container text-center">
                <span class="text-muted">Copyright © 2023 Espressif Systems</span>
            </div>
        </footer>
        <!-- Third party libraries-->
        <script src="node_modules/xterm/lib/xterm.js"></script>
        <script src="node_modules/xterm-addon-fit/lib/xterm-addon-fit.js"></script>
        <script src="node_modules/crypto-js/crypto-js.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.js"></script>
        <script type="text/javascript" src="node_modules/toml-js/src/toml.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>

        <script src="js/index.js" type="module"></script>
        <!-- Bootstrap core JS-->
        <script src="js/jquery.min.js"></script>
        <script src="js/bootstrap.bundle.min.js"></script>
        <script src="js/qrcode.min.js"></script>
        <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>-->
        <!-- Core theme JS-->
        <script src="js/scripts.js"></script>
    </body>
</html>
